//
//  INetDataCheckOperation.m
//  CToolBox
//
//  Created by SC on 16/11/30.
//  Copyright © 2016年 SC. All rights reserved.
//

#import "INetDataCheckOperation.h"

@implementation INetDataCheckOperation

+ (INetDataCheckOperation *)shareInstanceMethod
{
    static INetDataCheckOperation *shareInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareInstance = [[INetDataCheckOperation alloc] init];
    });
                
    return shareInstance;
}

- (void)checkObject:(NSDictionary *)object
       successBlock:(succeedBlock)success
       failureBlock:(failureBlock)failure
{
    DTOError *error = [[DTOError alloc] initWithDictionary:object error:nil];
    //判断error
    if (error) {//有错误
        //NSString *errorMessage = [self errorHandle:error];
        if (failure) {
            failure(error);
        }
    }else{
        if (success) {
            success(object);
        }
    }

}

/** 错误处理 */
- (NSString *)errorHandle:(ErrorModel *)error
{
    NSString *message = @"";
    if (error == nil) {
        return message;
    }
    
    //int errorNo = error.errorNo;
    if(error.isMultiError){
        for (MultiMessageModel *multiMessageModel in error.multiMessage) {
            message = [message stringByAppendingString:[NSString stringWithFormat:@",%@",multiMessageModel.message]];
        }
    }else{
        message = error.message;
    }
    
    return message;
}


@end
